package com.class05;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/servletB")
public class ServletB extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
//        从请求域中获取数据
        String name = (String) req.getAttribute("name");
        System.out.println("从请求域中获取数据为：" + name);
//         从会话域中获取数据
        Integer age = (Integer) req.getSession().getAttribute("age");
        System.out.println("从会话域中获取数据为：" + age);
//        从应用域中获取数据
        String address = (String) this.getServletContext().getAttribute("address");
        System.out.println("从应用域中获取数据：" + address);

    }
}
